// eslint-disable-next-line
import { suggestionsSelf } from '@/api/Account/community'

const community = {
  state: {
    proposalData: [],
    proposalParameter: {
      typeList: ['2'], // 1:吐槽 2:建议 3:帮助
      statusList: [], // 状态
      currentPage: 1, // 当前页
      pageSize: 5, // 每页显示条数
      order: 'desc' // desc:创建时间降序 asc：创建时间升序
    },
    complaintData: [],
    complaintParameter: {
      typeList: ['1'], // 1:吐槽 2:建议 3:帮助
      statusList: [], // 状态
      currentPage: 1, // 当前页
      pageSize: 5, // 每页显示条数
      order: 'desc' // desc:创建时间降序 asc：创建时间升序
    },
    assistData: [],
    assistParameter: {
      typeList: ['3'], // 1:吐槽 2:建议 3:帮助
      statusList: [], // 状态
      currentPage: 1, // 当前页
      pageSize: 5, // 每页显示条数
      order: 'desc' // desc:创建时间降序 asc：创建时间升序
    }
  },

  mutations: {
    SET_ProposalData: (state, data) => {
      state.proposalData = data
    },
    SET_ProposalParameter: state => {
      state.proposalParameter.currentPage = state.proposalParameter.currentPage + 1
    },
    SET_ComplaintData: (state, data) => {
      state.complaintData = data
    },
    SET_ComplaintParameter: state => {
      state.complaintParameter.currentPage = state.complaintParameter.currentPage + 1
    },
    SET_AssistData: (state, data) => {
      state.assistData = data
    },
    SET_AssistParameter: state => {
      state.assistParameter.currentPage = state.assistParameter.currentPage + 1
    }
  },

  actions: {
    /**
     * @param parameter
     * typeList	类型	否	list<varchar>	1:吐槽 2:建议 3:帮助
     * pageSize	数量	是	Integer
     * currentPage	当前页	是	Integer
     * statusList	状态	否	list<varchar>	0:未采纳
     * @returns {*}
     */
    // 我的圈子-分页查询建议
    suggestionsProposal({ commit, state }) {
      return new Promise((resolve, reject) => {
        suggestionsSelf(state.proposalParameter)
          .then(response => {
            const data = response.data
            commit('SET_ProposalData', data)
            commit('SET_ProposalParameter')
            resolve(response)
          })
          .catch(error => {
            reject(error)
          })
      })
    },
    // 我的圈子-分页查询吐槽
    suggestionsComplaint({ commit, state }) {
      return new Promise((resolve, reject) => {
        suggestionsSelf(state.complaintParameter)
          .then(response => {
            const data = response.data
            commit('SET_ComplaintData', data)
            commit('SET_ComplaintParameter')
            resolve(response)
          })
          .catch(error => {
            reject(error)
          })
      })
    },
    // 我的圈子-分页查询帮助
    suggestionsAssist({ commit, state }) {
      return new Promise((resolve, reject) => {
        suggestionsSelf(state.assistParameter)
          .then(response => {
            const data = response.data
            commit('SET_AssistData', data)
            commit('SET_AssistParameter')
            resolve(response)
          })
          .catch(error => {
            reject(error)
          })
      })
    }
  }
}

export default community
